package gui;

import gui.toolpanels.CFile;
import gui.toolpanels.CNode;

import java.awt.GridLayout;
import java.text.DateFormat;
import java.util.Locale;
import java.util.Vector;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import data.Files;



public class FileTable{
	public static JPanel GenerateTable(CNode node)
	{
		DateFormat dateFormatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM);
		Vector<Vector> tableData = new Vector<Vector>();
		Vector<String> cols = new Vector<String>();
		cols.add("Name");
		cols.add("Size");
		cols.add("Date modified");
		for(CFile f : node.getFile().children)
		{
			Vector<String> row = new Vector<String>();
			row.add(f.name);
			row.add(""+f.size);
			row.add(dateFormatter.format(f.modified));
			tableData.add(row);
			
		}
		
		JPanel panel = new JPanel(new GridLayout(1,0));
		JTable table = new JTable(tableData,cols);
	    table.setFillsViewportHeight(true);
	    //Create the scroll pane and add the table to it.
	    JScrollPane scrollPane = new JScrollPane(table);
	    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	    panel.add(table);
	    node.setPanel(panel);
	    return panel;
	}
}
